package com.shenglue.ssi.dao;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.shenglue.ssi.domain.BuyInMain;
import com.shenglue.ssi.domain.DicCat;

public  class DicCatDaoImpl extends SqlMapClientDaoSupport implements DicCatDao {

	/**
	 * 查询所有tb_DicCat 信息
	 */
	public List<DicCat> selectAllDicCat() {
		@SuppressWarnings("unchecked")
		List<DicCat> list = this.getSqlMapClientTemplate().queryForList(
		"selectAllDicCat");

		if (list != null && list.size() > 0) {
			return list;
		} else {
			return null;
		}
	}

	/**
	 * 增加tb_DicCat记录
	 */
	public boolean saveDicCat(DicCat diccat) {

		try {
			Object oRtn = this.getSqlMapClientTemplate().insert( "insertDicCat", diccat );
			// 已改正 来自网上的写法。已有文章讨论

			//插入成功 返回true
			return true;
		}
		catch ( DataAccessException e ) {
			//失败 返回false
			return false;
		}
	}


	/**
	 * 删除tb_DicCat记录
	 */
	public boolean deleteDicCat(int diccatId) {
		int flag= this.getSqlMapClientTemplate().delete("deleteDicCatById", diccatId);
		if( flag > 0 ) {
			return true;
		}
		return false;
	}

	/**
	 * 修改tb_DicCat记录
	 */
	public boolean updateDicCat(DicCat diccat) {

		int flag = this.getSqlMapClientTemplate().update("updateDicCat", diccat);
		if( flag > 0 ) {
			return true;
		}else{
			return false;
		}
	}

	/**
	 * 为修改，根据 Id 查一条 入库单主表记录
	 */
	public DicCat getOneDicCatForUpdate( int diccatId ) {
		Object oDicCat = this.getSqlMapClientTemplate().
		queryForObject( "getOneDicCatForUpdate", diccatId );

		DicCat diccat = (DicCat)oDicCat;

		return diccat;

	}

}
